package de.urlaub.server.data;

import java.io.Serializable;
import java.sql.Date;

import javax.interceptor.Interceptors;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import de.urlaub.server.logging.LoggingInterceptor;

@Entity
@Table(name="Vacation")
@Interceptors(LoggingInterceptor.class)
public class Vacation implements Serializable {

	private static final long serialVersionUID = 5698021006277957708L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int vacationId;
	@ManyToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "employeeId")
	private Employee employee;
	@Column(nullable=false)
	private Date fromDate;
	@Column(nullable=false)
	private Date tillDate;
	@Column(nullable=false)
	private int state;
	
	public Vacation (Employee employee, Date fromDate, Date tillDate, int state)
	{
		this.employee = employee;
		this.fromDate = fromDate;
		this.tillDate = tillDate;
		this.state = state;
	}

	public int getVacationId() {
		return vacationId;
	}

	public void setVacationId(int vacationId) {
		this.vacationId = vacationId;
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public Date getFromDate() {
		return fromDate;
	}

	public void setFromDate(Date fromDate) {
		this.fromDate = fromDate;
	}

	public Date getTillDate() {
		return tillDate;
	}

	public void setTillDate(Date tillDate) {
		this.tillDate = tillDate;
	}

	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}

	public static Vacation getVacationById(int id) {
		return new Vacation(new Employee("td", "Tobias", "Dehn", "pw", "uhpjee@gmail.com",
				new Division(1, "Marketing", false)), new Date(2012, 9, 27), new Date(2012, 9, 28), 0);
	}
}
